/**
 * 
 */
package ro.dta.idbi.model.tests;

import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.sql.SQLException;
import java.util.List;

import org.junit.Test;

import ro.dta.idbi.interfaces.IGraphIsomorphism;
import ro.dta.idbi.model.dynamicpattern.FloydWarshall;
import ro.dta.idbi.model.dynamicpattern.GraphHash;
import ro.dta.idbi.model.dynamicpattern.SDIsomorphism;
import ro.dta.idbi.model.dynamicpattern.Transaction;
import ro.dta.idbi.model.dynamicpattern.VFIsomorphism;
import uk.ac.ic.doc.automed.DSRException;

/**
 * Methods used to evaluate the pattern discovery method
 * 
 * @author Tudor Dobrila
 * 
 */
public class EvaluateTransaction {

	@Test
	public void testSD() throws DSRException, NoSuchAlgorithmException, ClassNotFoundException, IOException, SQLException {
		evaluateTrans(new SDIsomorphism(new FloydWarshall()));
	}

	public void testVF2() throws DSRException, NoSuchAlgorithmException, ClassNotFoundException, IOException, SQLException {
		evaluateTrans(new VFIsomorphism());
	}

	public void evaluateTrans(IGraphIsomorphism isoAlgorithm) throws DSRException, NoSuchAlgorithmException, IOException, SQLException, ClassNotFoundException {
		for (int t1 = 200; t1 <= 10000; t1 += 100) {
			for (int i = 0; i < 100; i++) {
				Transaction.generateTransaction(new GraphHash("MD5")).save();
			}

			Transaction newTrans = Transaction.loadTransactions("881e46453d5fe78774e243e9ae763f2d")
					.get(0);

			// Transaction newTrans = Transaction.generateTransaction();
			long total = 0, matches = 0;
			for (int i = 0; i < 30; i++) {
				long startTime = System.currentTimeMillis();
				List<Transaction> trans = Transaction
						.loadTransactions("881e46453d5fe78774e243e9ae763f2d");
				matches = trans.size();
				int[][] graph1 = newTrans.getSignature().getAdjacencyMatrix();
				for (Transaction t : trans) {
					int[][] graph2 = t.getSignature().getAdjacencyMatrix();
					isoAlgorithm.areIsomorphic(graph1, graph2);
				}
				long totalTime = System.currentTimeMillis() - startTime;
				total += totalTime;
			}

			System.out.println(t1 + "," + (total / 30.0) + "," + matches);
		}
	}

}
